package business;

import org.apache.log4j.Logger;

public class BasicAccount implements Account {
    // fields
    private final int id;
    // amount of money
    private double money;
    // logger
    private static final Logger LOGGER = Logger.getLogger(BasicAccount.class);
    // blocking flag
    private boolean isBlocked;

    // getters
    public int getId() {
        return id;
    }
    // get value
    public double getValue() {
        return money;
    }

    @Override
    public void setMoney(double money) {
        if (money < 0) {
            throw new IllegalArgumentException();
        }
        this.money = money;
    }

    public boolean isBlocked() { return isBlocked; }

    // constructors
    public BasicAccount(int id, double initialValue) {
        this.id = id;
        if (initialValue < 0) {
            throw new IllegalArgumentException();
        }
        money = initialValue;
    }

    public BasicAccount(int id) {
        this.id = id;
        money = 0.0;
    }

    // methods to inc/dec account money
    // return this to allow construct
    public Account increase(double value) {
        if (value < 0) {
            throw new IllegalArgumentException("Value to increase is less than zero");
        }
        money += value;
        return this;
    }

    // decrease account
    public Account decrease(double value) {
        // if current value less than
        if (money < value) {
            throw new IllegalArgumentException("Value to decrease is less than actual account money");
        }
        money -= value;
        return this;
    }

    public void setBlocked(boolean isBlocked) {
        this.isBlocked = isBlocked;
    }
}
